function [log_A,neglogLambda,etabar]=network(phi_vec,logphi_vec,W_mat,v_vec,alpha_vec,eta_vec)

% This function produces output: logA and -logLambda (TFP and Labor wedge)
% given input output matrix, technology and preference parameters, and shocks

global NsecGZ
onevec      =ones(NsecGZ,1);

a_vec       =inv(eye(NsecGZ)-transpose(((onevec-alpha_vec)*(onevec.')).*W_mat).*(onevec*transpose(phi_vec.*eta_vec))-v_vec*transpose(onevec-(phi_vec.*eta_vec)))*v_vec;
log_a       =log(a_vec);

B           =inv(eye(NsecGZ)-((eta_vec.*(onevec-alpha_vec))*(onevec.')).*W_mat);
q           =transpose((v_vec'*B).*(eta_vec'));
d           =transpose(v_vec'*((onevec*transpose(onevec-eta_vec)).*B));

psi         =(onevec')*((onevec-(phi_vec.*eta_vec)).*a_vec);
neglogLambda   =log(1+psi);

etabar      =1-(d'*onevec);
    
%Compute all the things
qlogphi     =q'*logphi_vec;
log_A    =qlogphi+neglogLambda-(d'*log_a);